package cn.imjzm.runcarserve.controller;

import cn.imjzm.runcarserve.pojo.SmokeData;
import cn.imjzm.runcarserve.service.SmokeService;
import cn.imjzm.runcarserve.pojo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@CrossOrigin(origins = "*")
@Tag(name = "MQ-2 烟雾传感器接口")
@RestController
@RequestMapping("/smoke")
public class SmokeController {

    @Autowired
    private SmokeService smokeService;

    @Operation(summary = "获取当前烟雾浓度与电压")
    @GetMapping("/get")
    public Result getSmokeData() {
        SmokeData data = smokeService.getRealTimeSmokeData();
        return Result.success(data);
    }
    @Operation(summary = "接收 Python 上传的 MQ-2 数据")
    @PostMapping("/receive")
    public Result receiveData(@RequestBody SmokeData data) {
        System.out.println("✅ 收到来自 Python 的数据：" + data);
        smokeService.updateRealTimeSmokeData(data); // 将数据缓存起来供 get() 查询
        return Result.success("接收成功");
    }
}
